using System;
using JetBrains.Annotations;
using UnityEngine.Scripting;
using Voodoo.Sauce.Core;

namespace Voodoo.Sauce.Internal
{
	[Preserve]
	public class NoAdsPurchaseDelegate : IPurchaseDelegateWithInfo, IPurchaseDelegateBase
	{
		private Action _OnPurchaseComplete;

		private Action _OnPurchaseFailure;

		public NoAdsPurchaseDelegate(Action onPurchaseComplete, Action onPurchaseFailure)
		{
			_OnPurchaseComplete = onPurchaseComplete;
			_OnPurchaseFailure = onPurchaseFailure;
		}

		public void OnInitializeSuccess()
		{
		}

		public void OnInitializeFailure(VoodooInitializationFailureReason reason)
		{
		}

		public void OnPurchaseComplete(ProductReceivedInfo productInfo, PurchaseValidation purchaseValidation)
		{
			if (productInfo.ProductId == VoodooSettings.Load().NoAdsBundleId)
			{
				_OnPurchaseComplete();
			}
		}

		public void OnPurchaseFailure(VoodooPurchaseFailureReason reason, [CanBeNull] ProductReceivedInfo productInfo, string description)
		{
			if (productInfo?.ProductId == VoodooSettings.Load().NoAdsBundleId)
			{
				_OnPurchaseFailure();
			}
		}
	}
}
